package com.cskaoyan.bean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author stone
 * @date 2021/11/16 17:23
 */
//就是我们上面案例的Support
public class CustomInvocationHandler implements InvocationHandler {

    //Ray ray = new Ray();
    Object target; //委托类对象

    public CustomInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //执行委托类方法
        //第一参数：委托类对象
        Object invoke = method.invoke(target, args);
        //增强
        System.out.println("买两个卤蛋" + method.getName());
        return invoke;
    }
}
